﻿using AntaresShell.NavigatorProvider;
using Windows.Storage;
using Windows.System;
using Windows.UI.ApplicationSettings;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace Antares.VIEWs
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class SettingPage
    {
        public SettingPage()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            IsTabStop = true;

            var temp = ApplicationData.Current.LocalSettings.Values["Tempurature"];
            if(temp == null || temp.ToString() == "F")
            {
                F_Radio.IsChecked = true;
            }
            else
            {
                C_Radio.IsChecked = true;
            }

            var lunar = ApplicationData.Current.LocalSettings.Values["Lunar"];
            if (lunar == null || lunar.ToString() == "Off")
            {
                Off_Radio.IsChecked = true;
            }
            else
            {
                On_Radio.IsChecked = true;
            }
        }

        private void backButton_Tapped(object sender, TappedRoutedEventArgs e)
        {
            Navigator.Instance.HidePopup();
            SettingsPane.Show();
        }

        private void PageKeyDown(object sender, KeyRoutedEventArgs e)
        {
            if (e.Key == VirtualKey.Tab)
            {
                IsTabStop = false;
                // backButton.IsTabStop = true;
            }
            else if (e.Key == VirtualKey.Escape)
            {
                Navigator.Instance.HidePopup();
            }
        }

        private void RadioButton_Checked_1(object sender, RoutedEventArgs e)
        {
            ApplicationData.Current.LocalSettings.Values["Tempurature"] = "F";
        }

        private void RadioButton_Checked_2(object sender, RoutedEventArgs e)
        {
            ApplicationData.Current.LocalSettings.Values["Tempurature"] = "C";
        }

        private void RadioButton_Checked_3(object sender, RoutedEventArgs e)
        {
            ApplicationData.Current.LocalSettings.Values["Lunar"] = "On";
        }

        private void RadioButton_Checked_4(object sender, RoutedEventArgs e)
        {
            ApplicationData.Current.LocalSettings.Values["Lunar"] = "Off";
        }
    }
}
